package com.demo.springBootDemo05.web;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.demo.springBootDemo05.entity.User;

@Controller
public class IndexController {
	@Value("${randomInt}")
	private Integer randomInt;
	
	@RequestMapping("/")
	@ResponseBody
	public Object index() {
		return "welcome";
	}
	
	@RequestMapping(value="/users", produces={MediaType.TEXT_HTML_VALUE})
	public String users(Model model) {
		model.addAttribute("users", User.listUser());
		model.addAttribute("randomInt", randomInt);
		return "users";
	}

	@RequestMapping("/hello/{name}")
	@ResponseBody
	public Object hello(@PathVariable("name") String name) {
		return String.format("Hello,%s", name);
	}

}
